package com.eshop.we.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.eshop.we.book.entity.Book;
import com.eshop.we.business.BookBusiness;
import com.eshop.we.business.UserBusiness;
import com.eshop.we.result.Result;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author wangzhanguo
 * @create 2018-06-05 10:54
 **/
@RestController
@RequestMapping("/user")
public class UserController extends BaseController{
    @Autowired
    private UserBusiness userBusiness;

    @Autowired
    private BookBusiness bookBusiness;

    @RequestMapping("/list")
    public Result list(){
        return Result.success(userBusiness.selectById(1));
    }

    @ApiOperation(value = "获取用户书架",notes = "根据状态获取用户书架")
    @ApiImplicitParams({
            @ApiImplicitParam(
                    name = "status",
                    required = true,
                    dataType = "Integer",
                    paramType = "query",
                    value = "10:已上架,20:已下架",
                    allowableValues = "",
                    allowMultiple = false
            )
    })
    @GetMapping("/userbooks")
    public Result getBookHome(@RequestParam(required = false) Integer status,@RequestParam(required = true) Integer userId){
        Book book=new Book();
        book.setStatus(status);
        book.setUserId(userId);
        book.setIsDel(0);
        EntityWrapper ew= new EntityWrapper<Book>();
        ew.setEntity(book);
        return Result.success(bookBusiness.selectList(ew));
    }

    /**
     * 用户主页信息
     * @return
     */
    @GetMapping("/getUserBooks")
    public Result getUserBooks(@RequestParam(required = true)Integer userId){
        return  Result.success(userBusiness.selectUserBooks(userId));
    }
}
